describe("MoveAmountController unit test for India", function() {
	var controller = null;
	
	beforeEach(function() {
		var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();
        var t_moveHolderCtrl = App.MoveHolderController.create();
        App.MoveAmountController.reopen({

            init:function(){
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
                this.set('controllers.moveHolder', t_moveHolderCtrl);
            }
        });

        controller = App.MoveAmountController.create();
	});

	it("prepareController - prepare with own transfer", function() {
		var transfer = App.OwnAccountTransfer.create();
		spyOn(App.getSession(), 'getCurrentTransfer').andReturn(transfer);
		
		controller.prepareController();
		
		expect(controller.isOtherDescription).toEqual(false);
	});
	
	it("prepareController - prepare with 3rdparty transfer", function() {
		var transfer = App.ThirdPartyTransfer.create();
        transfer.set('payee', Ember.Object.create({
            descriptionList : []
        }));
		spyOn(App.getSession(), 'getCurrentTransfer').andReturn(transfer);
        spyOn(App.RouteHistory, 'previousRoute').andReturn('move.from');
        spyOn(transfer, 'isRemarkFieldRequired').andReturn(true);

		controller.prepareController();

        expect(controller.isOtherDescription).toBeFalsy();
	});

    it("continueAction - ownAccount transfer ", function(){
        //prepare
        var transfer = App.OwnAccountTransfer.create();
        var _amount = '100';
        controller.set('amountVal', _amount);
        spyOn(App.getSession(), 'getCurrentTransfer').andReturn(transfer);
        spyOn(transfer, 'set');
        spyOn(transfer, 'validateAmount');
        spyOn(controller, 'transitionTo');

        //execute
        controller.continueAction();

        //verify
        expect(transfer.validateAmount).toHaveBeenCalledWith(_amount);
        expect(transfer.set).toHaveBeenCalledWith('amount', _amount);
        expect(controller.isOtherDescription).toBeFalsy();
        expect(controller.transitionTo).toHaveBeenCalledWith('move.when');
    });
    it("continueAction - thirdparty transfer ", function(){
        //prepare
        var transfer = App.ThirdPartyTransfer.create();
        var _amount = '1000';
        var _desc = 'test description';
        controller.set('amountVal', _amount);
        controller.set('description', _desc);
        spyOn(App.getSession(), 'getCurrentTransfer').andReturn(transfer);
        spyOn(transfer, 'set');
        spyOn(transfer, 'validateAmount');
        spyOn(controller, 'isOtherDescription').andReturn(true);
        spyOn(controller, 'transitionTo');

        //execute
        controller.continueAction();

        //verify
        expect(transfer.validateAmount).toHaveBeenCalledWith(_amount);
        expect(transfer.set).toHaveBeenCalledWith('amount', _amount);
        expect(transfer.set).toHaveBeenCalledWith('remark', _desc);
        expect(controller.transitionTo).toHaveBeenCalledWith('move.when');
    });

    it("continueAction - thirdparty transfer with empty description", function(){
        //prepare
        var transfer = App.ThirdPartyTransfer.create();
        var _amount = '1000';
        var _desc = '';
        controller.set('amountVal', _amount);
        controller.set('description', _desc);
        spyOn(App.getSession(), 'getCurrentTransfer').andReturn(transfer);
        spyOn(transfer, 'set');
        spyOn(transfer, 'validateAmount');
        spyOn(controller, 'isOtherDescription').andReturn(true);
        spyOn(controller, 'transitionTo');

        //execute
        controller.continueAction();

        //verify
        expect(transfer.validateAmount).toHaveBeenCalledWith(_amount);
        expect(transfer.set).toHaveBeenCalledWith('amount', _amount);
        expect(transfer.set).toHaveBeenCalledWith('remark', "Other");
        expect(controller.transitionTo).toHaveBeenCalledWith('move.when');
    });

    it("dropdownItemSelected - other", function() {

        var selectItem = {value:'Other'};
        spyOn(controller, 'set');
        controller.dropdownItemSelected(selectItem);

        expect(controller.set).toHaveBeenCalledWith('description', '');
        expect(controller.set).toHaveBeenCalledWith('isOtherDescription', true);
    });
    it("dropdownItemSelected - from List", function() {

        var selectItem = {value:'credit card payment'};
        spyOn(controller, 'set');
        controller.dropdownItemSelected(selectItem);

        expect(controller.set).toHaveBeenCalledWith('description', selectItem.value);
    });
	it("dropdownOpened", function() {
		spyOn(controller, 'set');

		controller.dropdownOpened();

		expect(controller.set).toHaveBeenCalled();
		expect(controller.showDescriptionInput).toBeFalsy();
	});
    it("dropdownClosed", function() {

        var selectItem = {value:'Other'};
        spyOn(controller, 'set');
        controller.dropdownClosed(selectItem);

        expect(controller.set).toHaveBeenCalledWith('showDescriptionInput', true);
    });

});